package cn.foraurora;

import cn.foraurora.api.BiliReply;
import cn.foraurora.entity.BiliReplyResponse;
import cn.foraurora.entity.Reply;
import cn.foraurora.entity.ReplyParam;
import com.alibaba.fastjson.JSON;
import com.dtflys.forest.Forest;

import java.util.Objects;

/**
 * @author huangchao
 * @date 2021/12/20
 */
public class GetCommentApplication {
//    private static Logger logger = Log.getInfoLogger(GetCommentApplication.class);

    public static void main(String[] args) {
        ReplyParam param = new ReplyParam();
        BiliReply client = Forest.client(BiliReply.class);
        String reply = client.getReply(param);
        BiliReplyResponse biliReplyResponse = JSON.parseObject(reply, BiliReplyResponse.class);
        System.out.println("all count : " + biliReplyResponse.getData().getCursor().getAll_count());
        int count = biliReplyResponse.getData().getReplies().length;
        double allCount = biliReplyResponse.getData().getCursor().getAll_count();
        int pageNum = (int) Math.ceil(allCount / 20);
        for (int i = 0; i < pageNum; i++) {
            param.setNext(param.getNext() + 1);
            Reply[] temp = JSON.parseObject(client.getReply(param), BiliReplyResponse.class).getData().getReplies();
            if (Objects.isNull(temp)) {
                break;
            }
            count += temp.length;
        }
        System.out.println("compute result : " + count);
    }
}
